_package("housing_loan_calculator.page");

_import("caf.ui.Page");
_import("caf.mui.ScrollView");

_class("HomePage", Page, function(){
	this._init = function(){
		_super._init.call(this);
	};
	this.create = function(parent){
		var obj = this.createTplElement(parent, "home.xml");
		this.init(obj);
		return obj;
	};
	this.init = function(){
		_super.init.apply(this, arguments);
		this.initComponents();
		this.initActionElements();
		this.initHousingLoanCalculator();
		this.initScrollview();
		
	};
	this.initHousingLoanCalculator = function(){

		window.setTimeout(function(){
			$('#welcome').fadeOut('slow', function() {
				$('#main').fadeIn('slow', function() {
					
				})
			});
		}, 2000)
		
		$.mobile.initializePage();
		
		
		//$("input[type='radio']").attr("checked",true).checkboxradio("refresh");
		var _self = this;
		$('#operate').delegate('#calculateLoan','click', function(ev){
			ev.preventDefault();
			calculate();
			_self._scrollview.scrollTo(-420);
			console.log(_self._scrollview);
		})

		$('#operate').delegate('#resetLoan','click', function(ev){
			reset();
			_self._scrollview.scrollTo(0);
		})
	};
	
	this.initScrollview = function(){
		this._scrollview = new ScrollView();
		this._scrollview.bind($E("home_content_wrapper"), {
			"parent": this,
			"id"    : "scroll1"
		});
		this.addListener(this._scrollview, "scrollEnd", this._scrollview, "onDefaultScrollEnd");

		//demo code
		this.addListener(this._scrollview, "scrollEnd", null, function(){
		  document.querySelector(".scroller").style.top;
		  //console.log(this);
		})
	};
	
	this.dispose = function(){
		_super.dispose.apply(this);
		this._scrollview.dispose();
		this._scrollview = null;
	};
});